package com.helloworld.fiberflax;

import com.helloworld.fiberflax.armor.FiberflaxHelmet;
import com.helloworld.fiberflax.inventory.GuiElementLoader;
import com.helloworld.fiberflax.tool.FiberfalxAxe;
import com.helloworld.fiberflax.tool.FiberflaxPickaxe;
import com.helloworld.fiberflax.weapon.FiberflaxSword;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import org.apache.logging.log4j.Logger;

@Mod.EventBusSubscriber(modid = Fiberflax.MODID)
@Mod(modid = Fiberflax.MODID, name = Fiberflax.NAME, version = Fiberflax.VERSION)
public class Fiberflax {
    public static final String MODID = "fiberflax";
    public static final String NAME = "Fiberflax";
    public static final String VERSION = "1.0";

    private static Logger logger;

    @Mod.Instance(Fiberflax.MODID)
    public static Fiberflax instance;
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) {
        logger = event.getModLog();
    }

    @EventHandler
    public void init(FMLInitializationEvent event) {
        new GuiElementLoader();
        logger.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    public static Item fiberflaxSeed;
    public static Item fiberflaxItem;
    public static Item fiberflaxHelmet;
    public static Item superflaxItem;
    public static Item fiberflaxRope;
    public static Item laval;
    public static Item Yamato;
    public static Item superflaxIngot;
    public static Item fiberflaxAxe;
    public static Item fiberflaxBag;
    public static Item fiberflaxPickaxe;

    public static Block blockFiberflax;

    /*注册物品*/
    @SubscribeEvent
    public static void registerItemAll(RegistryEvent.Register<Item> event) {
        event.getRegistry().register(
                fiberflaxSeed = new ItemBlock(blockFiberflax) {
                    @Override
                    public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
                        if (worldIn.getBlockState(pos).getBlock() == Blocks.FARMLAND) {
                            super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
                            return EnumActionResult.SUCCESS;
                        }
                        return EnumActionResult.PASS;
                    }
                }
                        .setRegistryName(new ResourceLocation(Fiberflax.MODID, "item_fiberflax_seed")).setUnlocalizedName("fiberflax_seed")
        );
        event.getRegistry().register(
                fiberflaxItem = new ItemFiberflax()
        );
        event.getRegistry().register(
                fiberflaxHelmet = new FiberflaxHelmet(ItemArmor.ArmorMaterial.LEATHER, 0, EntityEquipmentSlot.HEAD).setUnlocalizedName("item_fiberflax_helmet")
        );
        event.getRegistry().register(
                superflaxItem = new ItemSuperFiberflax()
        );
        event.getRegistry().register(
                fiberflaxRope = new FiberflaxRope()
        );
        event.getRegistry().register(
                laval = new Laval()
        );
        event.getRegistry().register(
                Yamato = new FiberflaxSword(Item.ToolMaterial.WOOD).setUnlocalizedName("item_fiberflax_sword")
        );
        event.getRegistry().register(
                superflaxIngot = new SuperFlaxIngot()
        );
        event.getRegistry().register(
                fiberflaxAxe = new FiberfalxAxe(Item.ToolMaterial.WOOD, 7.0F, -3.2F).setUnlocalizedName("item_fiberflax_axe")
        );
        event.getRegistry().register(
                fiberflaxBag = new FiberflaxBag().setUnlocalizedName("item_fiberflax_bag")
        );
        event.getRegistry().register(
                fiberflaxPickaxe =new FiberflaxPickaxe(Item.ToolMaterial.WOOD,1.0F,-2.8F).setUnlocalizedName("item_fiberflax_pickaxe")
        );
    }

    /*注册方块*/
    @SubscribeEvent
    public static void registerBlockAll(RegistryEvent.Register<Block> event) {
        event.getRegistry().register(
                blockFiberflax = new BlockFiberflax().setUnlocalizedName("block_fiberflax")
        );
    }

    public static final CreativeTabs FIBERFLAX_CREATIVE_TAB = new CreativeTabs("FiberFlax") {
        @Override
        public ItemStack getTabIconItem() {
            return new ItemStack(Fiberflax.fiberflaxItem);
        }
    };
}
